package com.bwie.task;

import com.bwie.domain.TbCoupon;
import com.bwie.mapper.TbCouponMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2024/11/16 10:44
 */

@Component
public class CouponExpireTask {

    @Autowired
    TbCouponMapper tbCouponMapper;

    /**
     * 每分钟检查一次，优惠券是否过期
     */
    @Scheduled(cron = "0 0/1 * * * ? ")
    public void checkCouponExpire(){
        System.out.println("检查优惠券是否过期");
        List<TbCoupon> expireList = tbCouponMapper.getExpireList();
        for (TbCoupon tbCoupon : expireList) {
            tbCoupon.setExpire(1);
            tbCouponMapper.updateById(tbCoupon);
        }
    }

}
